<?php

namespace common\models;

use Yii;

/**
 * Customize the simple Response class
 *
 * HTTP:200 =>  ok
 * HTTP:400 =>  No parameters found or missing
 * HTTP:404 =>  Not found result
 *
 */
class Responses {

    const COUNT_ONE = 1;
    const COUNT_ZERO = 0;

    /**
     * HTTP:200
     */
    public static function response200($res='', $count = self::COUNT_ONE, $message='') {
        return [
            'code' => 200,
            'message' => $message,
            'data' => [
                'count' => $count, 
                'res' => $res
            ]
        ];
    }

    /**
     * HTTP:400
     */
    public static function response400($message, $flag = false) {
        //$message = $flag ? $message : $message . ' Not found or missing';
        $message = $flag ? $message : $message . '';
        return [
            'code' => 400,
            'message' => $message,
            'data' => [
                'count' => self::COUNT_ZERO, 
                'res' => ''
            ]
        ];
    }

    /**
     * 失败传值$data
     * HTTP:400
     */
    public static function responseError($data = array(), $message = '', $flag = false) {
        $message = $flag ? $message : $message . ' Not found or missing';
        return [
            'code' => 400,
            'message' => $message,
            'data' => [
                'count' => self::COUNT_ZERO,
                'res' => $data
            ]
        ];
    }

    /**
     * HTTP:404
     */
    public static function response404($message='Not found result') {
        return [
            'code' => 404,
            'message' => $message,
            'data' => [
                'count' => self::COUNT_ZERO,
                'res' => []
            ]
        ];
    }


}
